<!DOCTYPE html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
  <title>HTML</title>

  <!-- Replace favicon.ico & apple-touch-icon.png in the root of your domain and delete these references -->
  <link rel="shortcut icon" href="/favicon.ico">
  <link rel="apple-touch-icon" href="/apple-touch-icon.png">
  <link rel="stylesheet" type="text/css" href="../../css/api.css" />
  <link rel="stylesheet" type="text/css" href="../../css/aui.css" />

	<style>
		html,body {width: 100%;height: 100%;background:transparent;}
.aui-mask {
  background: rgba(0,0,0,0)
}
.aui-popup {
  min-width: 0;
}
.aui-popup-arrow {
  background-color: #efeff4;
    background-image: -webkit-linear-gradient(45deg, #efeff4, #efeff4 50%, #efeff4 50%);
      background-image: linear-gradient(45deg, #efeff4, #efeff4 50%, #efeff4 50%);
}
.aui-list .aui-list-item {
      background-color: #efeff4;
}
.aui-list .aui-list-item-label-icon {
  padding: 0;
}
.aui-popup-content .aui-list img{
  display: inline-block;
  height: 1.0rem;
  width: 1.0rem;
  vertical-align: middle;
  margin-top: -5px;
}
	</style>
</head>

<body>

  <div class="aui-popup aui-popup-top-right" id="top-right">
    <div class="aui-popup-arrow"></div>
    <div class="aui-popup-content" id="more" v-cloak>
        <ul class="aui-list aui-list-noborder">
            <li class="aui-list-item" @click="fx()">
                <div class="aui-list-item-label-icon">
                      <img src="../../image/fx@3x.png" alt="">
                </div>
                <div class="aui-list-item-inner aui-list-item-middle">
                    分享
                </div>
            </li>
            <li v-if="isData == 0" class="aui-list-item"  @click="sc(1)">
                <div class="aui-list-item-label-icon">
                    <img src="../../image/shoucang@3x.png" alt="">
                </div>
                <div class="aui-list-item-inner">
                    收藏
                </div>
            </li>
            <li v-else class="aui-list-item"  @click="sc(0)">
                <div class="aui-list-item-label-icon">
                    <img src="../../image/shoucang2@3x.png" alt="">
                </div>
                <div class="aui-list-item-inner">
                    已收藏
                </div>
            </li>
        </ul>
    </div>
</div>

</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/aui-popup.js"></script>
<script type="text/javascript" src="../../script/zepto.js"></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript" src="../../script/utils.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script>

  function goback () {
    api.closeFrame({
        name: 'more'
    });

  }

	function match(src, target)
    {
        var mark = false;
        if(src === target){
            mark = true;
            return mark;
        }else{
            do{
                src = src.parentNode;
                if(src === target){
                    mark = true;
                    return mark;
                }
            }while(src !== document.body && src !== document.documentElement);

            return mark;
        }
    }
    apiready = function(){
        var body = $api.dom('body');
        var popup = new auiPopup();
        popup.show(document.getElementById("top-right"))
        $api.addEvt(body,'touchend',function(e){
            var main = $api.dom('.aui-mask')
            if(match(e.target, main))
            {
                api.closeFrame({name:'more'});
            }
        });


        var more = new Vue({
          el: '#more',
          data: {
            id: 0,
            type: '',
            info: {},
            token: 0,
            isData: 0,
            isCellectUrl: '',
            addCellectUrl: '',
            cancelCellectUrl: '',
          },
          created: function() {
            var $_this = this;
            if (!$api.getStorage('token')) {
                api.toast({
                    msg: '用户未登录',
                    duration: 2000,
                    location: 'middle'
                });
                api.closeFrame({name:'more'});
                return
            }
            $_this.id = api.pageParam.id
            $_this.type = api.pageParam.type
            if($_this.type == 'lw') {
              $_this.isCellectUrl = window.Url.isPaperLike
              $_this.addCellectUrl = window.Url.addPaperLike
              $_this.cancelCellectUrl = window.Url.cancelPaperLike
            } else if ($_this.type == 'kycg') {
              $_this.isCellectUrl = window.Url.isScientificLike
              $_this.addCellectUrl = window.Url.addScientificLike
              $_this.cancelCellectUrl = window.Url.cancelScientificLike
            } else if ($_this.type == 'hd') {
              $_this.isCellectUrl = window.Url.isCollect
              $_this.addCellectUrl = window.Url.addActivityCollect
              $_this.cancelCellectUrl = window.Url.cancelActivityCollect
            } else {
              $_this.isCellectUrl = window.Url.islikeCollectAndCount
              $_this.addCellectUrl = window.Url.addArticleCollect
              $_this.cancelCellectUrl = window.Url.cancelArticleCollect
            }
            $_this.token = $api.getStorage('token')
      // console.log($_this.id)
            $_this.issc()
          },
          methods: {
            issc:function() {
              var $_this = this;
              if ($_this.type == 'hd') {
                api.ajax({
                  url: $_this.isCellectUrl,
                  method: 'post',
                  headers: {
                    'Content-Type': 'application/json',
                    'baseParams': $_this.token //token
                  },
                  data: {
                    body: {
                      activityid: $_this.id
                    }
                  },
                  timeout: 300,
                }, function(ret, err) {
                    if (ret) {
                        if (ret.code == 5) {
                          $_this.isData = 0
                        } else if (ret.code == 0) {
                          $_this.isData = 1
                        } else {
                          api.alert({msg: ret});
                        }
                    } else {
                        api.alert({ msg: JSON.stringify(err) });
                    }
                })
              } else if ($_this.type == 'kycg') {
                api.ajax({
                  url: $_this.isCellectUrl + $_this.id,
                  headers: {
                    'baseParams': $_this.token //token
                  },
                  timeout: 300,
                }, function(ret, err) {
                    if (ret) {
                        // api.alert({msg: ret});
                        if (ret.code == 5) {
                          $_this.isData = 1
                        } else if (ret.code == 0) {
                          $_this.isData = 0
                        } else {
                          api.alert({msg: ret});
                        }
                    } else {
                        api.alert({ msg: JSON.stringify(err) });
                    }
                })
              } else {
                api.ajax({
                  url: $_this.isCellectUrl + $_this.id,
                  headers: {
                    'baseParams': $_this.token //token
                  },
                  timeout: 300,
                }, function(ret, err) {
                    if (ret) {
                      // api.alert({msg: ret})
                        // api.alert({msg: ret.data});
                        $_this.isData = ret.data.iscollect
                    } else {
                        api.alert({ msg: JSON.stringify(err) });
                    }
                })
              }
            },
             sc:function (is) {
               var $_this = this;
               if ($_this.type == 'lw') {
                 if(is == 1) {
                   api.ajax({
                     url: $_this.addCellectUrl,
                     method: 'POST',
                     headers: {
                       'Content-Type': 'application/json',
                       'baseParams': $_this.token //token
                     },
                     data:{
                       body:{
                         paper_id: $_this.id,
                         type: 1
                       }
                     },
                     timeout: 300,
                   }, function(ret, err) {
                       if (ret) {
                         if (ret.code == 0) {
                           $_this.addCellect()
                         } else {
                           api.alert({msg: ret.message})
                         }
                       } else {
                           api.alert({ msg: JSON.stringify(err) });
                       }
                   })
                 } else if(is == 0) {
                   api.ajax({
                     url: $_this.cancelCellectUrl + '1/' + $_this.id,
                     method: 'GET',
                     headers: {
                       'Content-Type': 'application/json',
                       'baseParams': $_this.token //token
                     },
                     timeout: 300,
                   }, function(ret, err) {
                       if (ret) {
                         if (ret.code == 0) {
                           $_this.cancelCellect()
                         } else {
                           api.alert({msg: ret.message})
                         }
                       } else {
                           api.alert({ msg: JSON.stringify(err) });
                       }
                   })
                 }
               } else if ($_this.type == 'hd') {
                 if(is == 1) {
                   api.ajax({
                     url: $_this.addCellectUrl,
                     method: 'POST',
                     headers: {
                       'Content-Type': 'application/json',
                       'baseParams': $_this.token //token
                     },
                     data:{
                       body:{
                         activityid: $_this.id
                       }
                     },
                     timeout: 300,
                   }, function(ret, err) {
                       if (ret) {
                           if (ret.code == 0) {
                             $_this.addCellect()
                           } else {
                             api.alert({msg: ret.message})
                           }
                       } else {
                           api.alert({ msg: JSON.stringify(err) });
                       }
                   })
                 } else if(is == 0) {
                   api.ajax({
                     url: $_this.cancelCellectUrl + $_this.id,
                     method: 'GET',
                     headers: {
                       'Content-Type': 'application/json',
                       'baseParams': $_this.token //token
                     },
                     timeout: 300,
                   }, function(ret, err) {
                       if (ret) {
                         if (ret.code == 0) {
                           $_this.cancelCellect()
                         } else {
                           api.alert({msg: ret.message})
                         }
                       } else {
                           api.alert({ msg: JSON.stringify(err) });
                       }
                   })
                 }
               } else if ($_this.type == 'kycg') {
                 if(is == 1) {
                   api.ajax({
                     url: $_this.addCellectUrl,
                     method: 'POST',
                     headers: {
                       'Content-Type': 'application/json',
                       'baseParams': $_this.token //token
                     },
                     data:{
                       body:{
                         scientific_id: $_this.id
                       }
                     },
                     timeout: 300,
                   }, function(ret, err) {
                       if (ret) {
                           if (ret.code == 0) {
                             $_this.addCellect()
                           } else {
                             api.alert({msg: ret.message})
                           }
                       } else {
                           api.alert({ msg: JSON.stringify(err) });
                       }
                   })
                 } else if(is == 0) {
                   api.ajax({
                     url: $_this.cancelCellectUrl + $_this.id,
                     method: 'GET',
                     headers: {
                       'Content-Type': 'application/json',
                       'baseParams': $_this.token //token
                     },
                     timeout: 300,
                   }, function(ret, err) {
                       if (ret) {
                         if (ret.code == 0) {
                           $_this.cancelCellect()
                         } else {
                           api.alert({msg: ret.message})
                         }
                       } else {
                           api.alert({ msg: JSON.stringify(err) });
                       }
                   })
                 }
               } else {
                 if(is == 1) {
                   api.ajax({
                     url: $_this.addCellectUrl,
                     method: 'POST',
                     headers: {
                       'Content-Type': 'application/json',
                       'baseParams': $_this.token //token
                     },
                     data:{
                       body:{
                         article_id: $_this.id
                       }
                     },
                     timeout: 300,
                   }, function(ret, err) {
                       if (ret) {
                           if (ret.code == 0) {
                             $_this.addCellect()
                           } else {
                             api.alert({msg: ret.message})
                           }
                       } else {
                           api.alert({ msg: JSON.stringify(err) });
                       }
                   })
                 } else if(is == 0) {
                   api.ajax({
                     url: $_this.cancelCellectUrl + $_this.id,
                     method: 'GET',
                     headers: {
                       'Content-Type': 'application/json',
                       'baseParams': $_this.token //token
                     },
                     timeout: 300,
                   }, function(ret, err) {
                       if (ret) {
                         if (ret.code == 0) {
                           $_this.cancelCellect()
                         } else {
                           api.alert({msg: ret.message})
                         }
                       } else {
                           api.alert({ msg: JSON.stringify(err) });
                       }
                   })
                 }
               }


            },
            addCellect: function () {
              var $_this = this;
              api.openFrame ({
                name: 'collection',
                url: './collection.html',
                pageParam:{title: "已收藏"},
                rect:{
                  x:0,
                  y:0,
                  w:'auto',
                  h:'auto'
                },
                bounces: false,
                delay:200
              })
              $_this.issc()
                api.closeFrame({name:'more'});
            },
            cancelCellect: function () {
              var $_this = this;
              api.openFrame ({
                name: 'collection',
                url: './collection.html',
                pageParam:{title: "已取消收藏"},
                rect:{
                  x:0,
                  y:0,
                  w:'auto',
                  h:'auto'
                },
                bounces: false,
                delay:200
              })
              $_this.issc()
             api.closeFrame({name:'more'});
            },
            fx: function () {
                api.openFrame ({
                        name: 'share',
                        url: './share.html',
                        rect:{
                            x:0,
                            y:0,
                            w:'auto',
                            h:'auto'
                        },
                        bounces: false,
                        delay:200
                    })
                      api.closeFrame({name:'more'});
              }
          }
        })

    }
</script>
</html>
